package com.yanqu.road.listener;

import com.yanqu.road.AgentServer;
import io.netty.channel.Channel;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;


/**
 * @Author wpj
 * @Date 2020/12/9
 */
public class DelayCloseGenericFutureListener {

    Channel channel;

    private GenericFutureListener<Future<? super Void>> listener;

    public DelayCloseGenericFutureListener(Channel channel) {
        this.channel = channel;
        listener = new GenericFutureListener<Future<? super Void>>() {
            public void operationComplete(Future<? super Void> future) throws Exception {
                AgentServer.getTimerExecutorService().execute(() -> {
                    try {
                        Thread.sleep(5);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    channel.close();
                });
            }
        };
    }

    public Channel getChannel() {
        return channel;
    }

    public GenericFutureListener<Future<? super Void>> getListener() {
        return listener;
    }
}
